package com.nanbei.a03;

import java.util.ArrayList;

/**
 * @ClassDescription: 模板方法 设计模式
 * @JdkVersion: 17
 * @Author: BaoShan.Li
 * @Date: 2024/11/12 22:49
 */
public class TestMethodTemplate {
    public static void main(String[] args) {
        MyBeanFactory myBeanFactory = new MyBeanFactory();
        myBeanFactory.addBeanPostProcess(bean -> {
            System.out.println("@Autowired 注解解析");
        });
        myBeanFactory.addBeanPostProcess(bean -> {
            System.out.println("@Resource 注解解析");
        });
        myBeanFactory.getBean();
    }

    static class MyBeanFactory{
        private ArrayList<BeanPostProcess> processList = new ArrayList<>();
        public Object getBean(){
            Object bean = new Object();
            System.out.println("构造 "+bean);
            System.out.println("依赖注入 "+bean);
            for (BeanPostProcess process : processList) {
                process.inject(bean);
            }
            System.out.println("初始化 "+bean);
            return bean;
        }

        public  void addBeanPostProcess(BeanPostProcess postProcess){
            processList.add(postProcess);
        }
    }


    static interface BeanPostProcess{
        public void inject(Object bean);
    }
}
